package com.my.interceptor;

import org.apache.catalina.Session;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Zhang on 2018/8/26.
 */
public class Sessioninterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
/*    System.out.println(request.getRequestURI());
    String base=request.getContextPath();
        if (request.getRequestURI().equals(base+"/user/login")||request.getRequestURI().equals(base+"/user/main")){
        return  true;
    }*/
        HttpSession session=request.getSession();
          if (session.getAttribute("user")!=null){
              return true;
          }else{
              if(request.getRequestURI().equals("/Zhang/motherNursing/editWord")){
                  return true;
              }
              response.sendRedirect(request.getContextPath()+"/user/main");
              return  false;
          }


    }
}
